import { useRef } from 'react'
import { IPageContentRef } from '@/components/page-content'
import { FormInstance } from 'antd'
import { formatTime } from '@/utils/format'

function usePageSearch() {
  const pageContentRef = useRef<IPageContentRef>(null)

  function searchClick(form: FormInstance | undefined) {
    const formData = form?.getFieldsValue()
    // 对表单中的日期选择器数据进一步处理，处理完再发请求
    if (formData.createTime) {
      formData.createTime = formatTime(formData.createTime.$d)
    }
    pageContentRef.current?.getPageData(formData)
  }

  function resetClick(form: FormInstance | undefined) {
    form?.resetFields()
  }

  return { pageContentRef, searchClick, resetClick }
}

export default usePageSearch
